<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="支付订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入支付订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结算金额" prop="finalAmount">
        <el-input
          v-model="queryParams.finalAmount"
          placeholder="请输入结算金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付金额" prop="payAmount">
        <el-input
          v-model="queryParams.payAmount"
          placeholder="请输入支付金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务订单号" prop="businessplan">
        <el-input
          v-model="queryParams.businessplan"
          placeholder="请输入业务订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易对手" prop="tradeUser">
        <el-input
          v-model="queryParams.tradeUser"
          placeholder="请输入交易对手"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <div>
        <el-form-item label="发起交易日期">
          <div class="block">
            <el-date-picker
              v-model="queryParams.fqStartTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              clearable
              placeholder="选择日期时间">
            </el-date-picker>至
            <el-date-picker
              v-model="queryParams.fqEndTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              placeholder="选择日期时间"
              clearable>
            </el-date-picker>
          </div>
        </el-form-item>
      </div>
      <el-form-item label="交易账号" prop="tradeAccount">
        <el-input
          v-model="queryParams.tradeAccount"
          placeholder="请输入交易账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="对手账户" prop="dsAccount">
        <el-input
          v-model="queryParams.dsAccount"
          placeholder="请输入对手账户"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <div>
        <el-form-item label="支付截止日期">
          <div class="block">
            <el-date-picker
              v-model="queryParams.zfStartTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              clearable
              placeholder="选择日期时间">
            </el-date-picker>至
            <el-date-picker
              v-model="queryParams.zfEndTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              placeholder="选择日期时间"
              clearable>
            </el-date-picker>
          </div>
        </el-form-item>
      </div>
      <el-form-item label="交易渠道" prop="tradeQudao">
        <el-input
          v-model="queryParams.tradeQudao"
          placeholder="请输入交易渠道"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易账号类型" prop="tradeAccountType">
        <el-select v-model="queryParams.tradeAccountType" placeholder="请选择交易账号类型" clearable size="small">
          <el-option v-for="item in tradeAccountTypes" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="渠道订单号" prop="qudaoOrderNo">
        <el-input
          v-model="queryParams.qudaoOrderNo"
          placeholder="请输入渠道订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户类型" prop="userType">
        <el-select v-model="queryParams.userType" placeholder="请选择交易账号类型" clearable size="small">
          <el-option v-for="item in userTypes" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="交易结果" prop="tradeAccountType">
        <el-select v-model="queryParams.tradeResult" placeholder="请选择交易结果" clearable size="small">
          <el-option v-for="item in tradeResults" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式" prop="payWay">
        <el-select v-model="queryParams.payWay" placeholder="请选择支付方式" clearable size="small">
          <el-option v-for="item in payWaies" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入订单金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:order:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column
        prop="orderNo"
        label="交易流水号"
        width="200">
      </el-table-column>
      <el-table-column
        label="交易账户类型">
        <template slot-scope="scope">
          <span v-if="scope.row.tradeAccountType=='1'">微信</span>
          <span v-if="scope.row.tradeAccountType=='2'">支付宝</span>
          <span v-if="scope.row.tradeAccountType=='3'">银行卡</span>
          <span v-if="scope.row.tradeAccountType=='4'">卡拉卡</span>
        </template>
      </el-table-column>
      <el-table-column
        label="用户类型">
        <template slot-scope="scope">
          <span v-if="scope.row.userType=='1'">个人用户</span>
          <span v-if="scope.row.userType=='2'">企业商户</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="tradeAccountNo"
        label="交易账号">
      </el-table-column>
      <el-table-column
        prop="tradeAccount"
        label="交易账户">
      </el-table-column>
      <el-table-column
        label="支付方式">
        <template slot-scope="scope">
          <span v-if="scope.row.payWay=='1'">微信扫码</span>
          <span v-if="scope.row.payWay=='2'">支付宝扫码</span>
          <span v-if="scope.row.payWay=='3'">微信公众号</span>
          <span v-if="scope.row.payWay=='4'">微认证支付</span>
          <span v-if="scope.row.payWay=='5'">实时代付到银行卡</span>
          <span v-if="scope.row.payWay=='20'">批量代付到银行卡</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="tradeUser"
        label="交易对手">
      </el-table-column>
      <el-table-column
        prop="dsAccount"
        label="对手账号"
        width="200">
      </el-table-column>
      <el-table-column
        prop="tradeQudao"
        label="交易渠道">
      </el-table-column>
      <el-table-column
        prop="qudaoOrderNo"
        label="渠道订单号"
        width="250">
      </el-table-column>
      <el-table-column
        label="交易结果">
        <template slot-scope="scope">
          <span v-if="scope.row.tradeResult=='1'">处理中</span>
          <span v-if="scope.row.tradeResult=='2'">成功</span>
          <span v-if="scope.row.tradeResult=='3'">失败</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="tradeDateFq"
        label="发起交易日期"
        width="150">
      </el-table-column>
      <el-table-column
        prop="tradeDateJz"
        label="支付截止日期"
        width="150">
      </el-table-column>
      <el-table-column
        prop="commissionFee"
        label="手续费">
      </el-table-column>
      <el-table-column
        prop="payAmount"
        label="支付金额">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:order:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/finance/order";

export default {
  name: "Order",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 支付订单（支付流水信息）表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
      },
      // 表单参数
      form: {},
      //交易账户类型
      tradeAccountTypes:[
        {id:1,name:"微信"},
        {id:2,name:"支付宝"},
        {id:3,name:"银行卡"},
        {id:4,name:"卡拉卡"}
      ],
      //用户类型
      userTypes:[
        {id:1,name:"个人用户"},
        {id:2,name:"企业商户"}
      ],
      //交易结果
      tradeResults:[
        {id:1,name:"处理中"},
        {id:2,name:"成功"},
        {id:3,name:"失败"},
      ],
      //支付方式
      payWaies:[
        {id:1,name:"微信扫码"},
        {id:2,name:"支付宝扫码"},
        {id:3,name:"微信公众号"},
        {id:4,name:"认证支付"},
        {id:5,name:"实时代付到银行卡"},
        {id:20,name:"批量代付到银行卡"},
      ]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询支付订单（支付流水信息）列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        tradeAccount: null,
        tradeAccountType: null,
        tradeAccountNo: null,
        userId: null,
        userType: null,
        operationType: null,
        payWay: null,
        amount: null,
        payAmount: null,
        finalAmount: null,
        discountAmount: null,
        tradeUser: null,
        dsAccount: null,
        tradeQudao: null,
        qudaoOrderNo: null,
        tradeResult: null,
        returnCode: null,
        returnMsg: null,
        tradeDateFq: null,
        tradeDateZx: null,
        tradeDateZf: null,
        tradeDateJz: null,
        tradeRate: null,
        commissionFee: null,
        beginTime: null,
        endTime: null,
        checkState: null,
        checkTime: null,
        checkUserid: null,
        checkFailReason: null,
        outOrderNo: null,
        dzState: null,
        certificateJz: null,
        productSubject: null,
        productBody: null,
        canClearingAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加支付订单（支付流水信息）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改支付订单（支付流水信息）";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除支付订单（支付流水信息）编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrder(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/order/export', {
        ...this.queryParams
      }, `system_order.xlsx`)
    }
  }
};
</script>
